/*
 * Copyright 2012 Gregor Schauer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package at.schauer.gregor.vienna.datastore;

import at.schauer.gregor.vienna.AbstractViennaIT;
import at.schauer.gregor.vienna.test.SimpleObject;
import org.junit.Before;
import org.junit.Test;

import java.io.Serializable;
import java.util.UUID;

import static org.junit.Assert.assertEquals;

/**
 * @author Gregor Schauer
 */
public abstract class AbstractDataStoreIT extends AbstractViennaIT {
	protected DataStore<Serializable> dataStore;

	@Before
	public abstract void before();

	@Test
	public void test() {
		SimpleObject obj = new SimpleObject(UUID.randomUUID(), true, (byte) 1, (char) 1, (short) 1, 1, 1L, 1f, 1.0);

		Object save = dataStore.save(obj);
		assertEquals(obj.getId(), save);
		assertEquals(1, dataStore.list(obj.getClass()).size());

		assertEquals(obj.getId(), dataStore.save(obj));

		SimpleObject load = dataStore.load(obj.getClass(), obj.getId());
		assertEquals(obj, load);

		dataStore.delete(obj);
		assertEquals(0, dataStore.list(obj.getClass()).size());
	}
}
